package niuke;

import java.util.Scanner;

public class Test4 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] strs = line.split("-");

		String str1 = strs[0].trim();
		String str2 = strs[1].trim();
		int m1 = getindex(str1.split(" ")[0]);
		int m2 = getindex(str2.split(" ")[0]);
		// 双王
		if (m1 == 16) {
			System.out.println(str1);
			return;
		}
		if (m2 == 16) {
			System.out.println(str2);
			return;
		}
		// 4张牌和其他拍的比较
		if (str1.length() == 7 && str2.length() != 7) {
			System.out.println(str1);
			return;
		}

		if (str2.length() == 7 && str1.length() != 7) {
			System.out.println(str1);
			return;
		}
		// 比较个子 顺子 三个 双炸弹 的大小
		if (1 == str1.split(" ").length && 1 == str2.split(" ").length
				|| 5 == str1.split(" ").length && 5 == str2.split(" ").length
				|| 3 == str1.split(" ").length && 3 == str2.split(" ").length
				|| 4 == str1.split(" ").length && 4 == str2.split(" ").length
				|| 2 == str1.split(" ").length && 2 == str2.split(" ").length) {
			System.out.println(m1 > m2 ? str1 : str2);
			return;
		}
		System.out.println("ERROR");

	}

	private static int getindex(String str) {
		if (str.equals("J")) {
			return 11;
		} else if (str.equals("Q")) {
			return 12;
		} else if (str.equals("K")) {
			return 13;
		} else if (str.equals("A")) {
			return 14;
		} else if (str.equals("2")) {
			return 15;
		} else if (str.equalsIgnoreCase("joker")) {
			return 16;
		} else {
			return Integer.parseInt(str);
		}
	}
}
